9月 6 2017 Online Judge►LeetCode [LeetCode] 102 - Binary Tree Level Order Traversal 題意Level Order Traversal 二元樹。 解法BFS。 程式123456789101112131415161718192021222324252627/** * Definition for a binary tree node. * function TreeNode(val) { * this.val = val; * this.left = this.right = null; * } *//** * @param {TreeNode} root * @return {number[][]} */var levelOrder = function(root) { if ( !root ) return []; let queue = [root]; let levels = []; while( queue.length !== 0 ){ let length = queue.length; levels.push([]); for ( let i = 0; i < length; i ++ ){ let node = queue.shift(); levels[levels.length-1].push(node.val); if ( node.left ) queue.push(node.left); if ( node.right ) queue.push(node.right); } } return levels;}; Newer [LeetCode] 98 - Validate Binary Search Tree Older [LeetCode] 141 - Linked List Cycle